/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kaytto1;

import com.sun.lwuit.Component;
import com.sun.lwuit.Form;
import com.sun.lwuit.Label;
import com.sun.lwuit.TextArea;
import com.sun.lwuit.layouts.BoxLayout;

/**
 *
 * @author Joteitti
 */
public class ConfirmationForm extends Form {

    private HomeService homeService;
    private Label nameLabel;
    private TextArea nameTextArea;
    private Label addressLabel;
    private TextArea addressTextArea;
    private Label phoneNumberLabel;
    private TextArea phoneNumberTextArea;
    private Label emailLabel;
    private TextArea emailTextArea;
    private Label problemLabel;
    private TextArea problemTextArea;
    private Label imagesLabel;
    private TextArea imagesTextArea;
    private Label emptyLabel;

    public ConfirmationForm(HomeService homeService) {
        super();

        // Set home service
        this.homeService = homeService;

        // Create form layout and components
        setTitle(Text.getString(Text.TEXT_CONFIRMATION_TITLE));
        addCommandListener(homeService);
        addCommand(homeService.getSendCommand());
        addCommand(homeService.getBackCommand());
        setTransitionOutAnimator(homeService.getTransition());
        setFocusScrolling(true);
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));
        addComponent(getNameLabel());
        addComponent(getNameTextArea());
        addComponent(getAddressLabel());
        addComponent(getAddressTextArea());
        addComponent(getPhoneNumberLabel());
        addComponent(getPhoneNumberTextArea());
        addComponent(getEmailLabel());
        addComponent(getEmailTextArea());
        addComponent(getProblemLabel());
        addComponent(getProblemTextArea());
        addComponent(getImagesLabel());
        addComponent(getImagesTextArea());
        addComponent(getEmptyLabel());
    }

    public void updateTexts() {
        int imageCount = homeService.getImageForm().getImageCount();
        imagesLabel.setText(Text.getString(Text.TEXT_CONFIRMATION_IMAGES) + String.valueOf(imageCount));
        imagesTextArea.setText(String.valueOf(imageCount));
        imagesTextArea.setVisible(false);
        problemTextArea.setText(homeService.getBasicForm().getProblem());
        emailTextArea.setText(homeService.getBasicForm().getEmail());
        phoneNumberTextArea.setText(homeService.getBasicForm().getPhoneNumber());
        addressTextArea.setText(homeService.getBasicForm().getFullAddress());
        nameTextArea.setText(homeService.getBasicForm().getName());
    }

    private Label getNameLabel() {
        // Lazy initialization
        if(nameLabel == null) {
            nameLabel = new Label(Text.getString(Text.TEXT_CONFIRMATION_NAME));
            nameLabel.setAlignment(Component.LEFT);
        }

        return nameLabel;
    }

    private TextArea getNameTextArea() {
        // Lazy initialization
        if(nameTextArea == null) {
            nameTextArea = new TextArea();
            nameTextArea.setSingleLineTextArea(true);
            nameTextArea.setEditable(false);
            nameTextArea.setFocusable(false);
        }

        return nameTextArea;
    }

    private Label getAddressLabel() {
        // Lazy initialization
        if(addressLabel == null) {
            addressLabel = new Label(Text.getString(Text.TEXT_CONFIRMATION_FULL_ADDRESS));
            addressLabel.setAlignment(Component.LEFT);
        }

        return addressLabel;
    }

    private TextArea getAddressTextArea() {
        // Lazy initialization
        if(addressTextArea == null) {
            addressTextArea = new TextArea();
            addressTextArea.setSingleLineTextArea(false);
            addressTextArea.setEditable(false);
            addressTextArea.setFocusable(false);
        }

        return addressTextArea;
    }

    private Label getPhoneNumberLabel() {
        // Lazy initialization
        if(phoneNumberLabel == null) {
            phoneNumberLabel = new Label(Text.getString(Text.TEXT_CONFIRMATION_PHONE_NUMBER));
            phoneNumberLabel.setAlignment(Component.LEFT);
        }

        return phoneNumberLabel;
    }

    private TextArea getPhoneNumberTextArea() {
        // Lazy initialization
        if(phoneNumberTextArea == null) {
            phoneNumberTextArea = new TextArea();
            phoneNumberTextArea.setSingleLineTextArea(true);
            phoneNumberTextArea.setEditable(false);
            phoneNumberTextArea.setFocusable(false);
        }

        return phoneNumberTextArea;
    }

    private Label getEmailLabel() {
        // Lazy initialization
        if(emailLabel == null) {
            emailLabel = new Label(Text.getString(Text.TEXT_CONFIRMATION_EMAIL));
            emailLabel.setAlignment(Component.LEFT);
        }

        return emailLabel;
    }

    private TextArea getEmailTextArea() {
        // Lazy initialization
        if(emailTextArea == null) {
            emailTextArea = new TextArea();
            emailTextArea.setSingleLineTextArea(true);
            emailTextArea.setEditable(false);
            emailTextArea.setFocusable(false);
        }

        return emailTextArea;
    }

    private Label getProblemLabel() {
        // Lazy initialization
        if(problemLabel == null) {
            problemLabel = new Label(Text.getString(Text.TEXT_CONFIRMATION_PROBLEM));
            problemLabel.setAlignment(Component.LEFT);
        }

        return problemLabel;
    }

    private TextArea getProblemTextArea() {
        // Lazy initialization
        if(problemTextArea == null) {
            problemTextArea = new TextArea();
            problemTextArea.setSingleLineTextArea(false);
            problemTextArea.setEditable(false);
            problemTextArea.setFocusable(false);
        }

        return problemTextArea;
    }

    private Label getImagesLabel() {
        // Lazy initialization
        if(imagesLabel == null) {
            imagesLabel = new Label(Text.getString(Text.TEXT_CONFIRMATION_IMAGES));
            imagesLabel.setAlignment(Component.LEFT);
        }

        return imagesLabel;
    }

    private TextArea getImagesTextArea() {
        // Lazy initialization
        if(imagesTextArea == null) {
            imagesTextArea = new TextArea();
            imagesTextArea.setSingleLineTextArea(true);
            imagesTextArea.setEditable(false);
            imagesTextArea.setFocusable(false);
        }

        return imagesTextArea;
    }

        private Label getEmptyLabel() {
        // Lazy initialization
        if(emptyLabel == null) {
            emptyLabel = new Label();
            emptyLabel.setAlignment(Component.LEFT);
        }

        return emptyLabel;
    }
}